﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIT.Controls.Containers;

namespace UIT
{
    public class ContainerRenderer : IControlRenderer<IContainer>
    {
        public ContainerRenderer()
        {

        }

        #region IRenderer<IContainer> Members

        public void Render(IContainer control)
        {
            foreach (var child in control.Children)
            {
                var renderer = Manager.GetRenderer(child);
                renderer.Render(child);
            }
        }

        #endregion

        #region IRenderer Members

        public RendererManager Manager { get; set; }

        #endregion

        #region IRenderer Members


        public void Render(Controls.IControl child)
        {
            IContainer container = child as IContainer;
            if (container == null)
                throw new NotSupportedException();
            Render(container);
        }

        #endregion

        #region IVisitor<IContainer> Members

        public void Visit(IContainer visitable)
        {
            Render(visitable);
        }

        #endregion

        #region IRenderer Members


        public virtual void Initialize(RendererManager manager, object userObject)
        {
            Manager = manager;
        }

        #endregion
    }
}
